package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;

import org.cbg.until.TraslationDemoScrollBarUI;
import org.come.until.CutButtonImage;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.TaoBaoBtn;
import com.tool.tcpimg.UIUtils;

public class DailyLoginJPanel extends JPanel {

	private String[] menuName = { "每日签到", "周/月卡领奖" };
	private TaoBaoBtn[] menuBtn = new TaoBaoBtn[2];

	private int menuType = 1; // 每日签到1 周/月卡领奖2

	private JLabel menuStr; // 滚动栏名称

	private JScrollPane scrollPane;

	private TaoBaoBtn customBtn; // 自定义按钮

	private DailyLoginGoodsJpanel[] dailyLoginGoodsJpanel = new DailyLoginGoodsJpanel[31];

	public DailyLoginJPanel() {
		// TODO Auto-generated constructor stub
		this.setPreferredSize(new Dimension(589, 479));
		this.setLayout(null);
		this.setOpaque(false);
		// 关闭按钮事件
		FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 86);
		offBtn.setBounds(564, 3, 25, 25);
		this.add(offBtn);

		for (int i = 0; i < menuBtn.length; i++) {
			menuBtn[i] = new TaoBaoBtn("skin/8100226/button/6.png", 1, menuName[i], i + 60, this);
			menuBtn[i].setBounds(60 + i * 72, 22, 70, 35);
			menuBtn[i].setOpaque(false);
			this.add(menuBtn[i]);
		}
		try {
			menuBtn[0].setIcons(CutButtonImage.cuts("skin/8100226/button/5.png"));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// 申请列表滚动条
		scrollPane = new JScrollPane();
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		/** 7-16-HGC-start */
		scrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(scrollPane));
		/** 7-16-HGC-end */
		scrollPane.getVerticalScrollBar().setUnitIncrement(30);
		scrollPane.getViewport().setOpaque(false);
		scrollPane.setOpaque(false);
		scrollPane.setBounds(48, 97, 522, 359);
		scrollPane.setBorder(BorderFactory.createEmptyBorder());
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		JPanel jPanel = new JPanel();
		jPanel.setOpaque(false);
		jPanel.setLayout(null);

		for (int i = 0; i < dailyLoginGoodsJpanel.length; i++) {
			int row = i / 2;
			int rank = i % 2;
			dailyLoginGoodsJpanel[i] = new DailyLoginGoodsJpanel();
			dailyLoginGoodsJpanel[i].setBounds(rank * 259 + 0, row * 65 + 0, 250, 65);
			jPanel.add(dailyLoginGoodsJpanel[i]);

		}
		jPanel.setPreferredSize(new Dimension(656, 65 * (dailyLoginGoodsJpanel.length / 2 + 1)));
		scrollPane.setViewportView(jPanel);
		this.add(scrollPane);
		scrollPane.updateUI();
		scrollPane.invalidate();
		scrollPane.validate();
		scrollPane.repaint();

		this.add(getMenuStr());
		this.add(getCustomBtn());

	}

	private ImageIcon iconBack;

	@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
		super.paintComponent(g);
		if (iconBack == null) {
			iconBack = new ImageIcon("inkImg/old/background/56.png");
		}
		g.drawImage(iconBack.getImage(), 0, 0, 589, 479, this);

	}

	public String[] getMenuName() {
		return menuName;
	}

	public void setMenuName(String[] menuName) {
		this.menuName = menuName;
	}

	public TaoBaoBtn[] getMenuBtn() {
		return menuBtn;
	}

	public void setMenuBtn(TaoBaoBtn[] menuBtn) {
		this.menuBtn = menuBtn;
	}

	public int getMenuType() {
		return menuType;
	}

	public void setMenuType(int menuType) {
		this.menuType = menuType;
	}

	public JLabel getMenuStr() {
		if (menuStr == null) {
			menuStr = new JLabel();
			menuStr.setOpaque(false);
			menuStr.setBounds(45, 78, 522, 20);
			menuStr.setForeground(Color.white);
			menuStr.setFont(UIUtils.TEXT_HY17);
			menuStr.setText(menuName[0]);
			menuStr.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return menuStr;
	}

	public void setMenuStr(JLabel menuStr) {
		this.menuStr = menuStr;
	}

	public JScrollPane getScrollPane() {
		return scrollPane;
	}

	public void setScrollPane(JScrollPane scrollPane) {
		this.scrollPane = scrollPane;
	}

	public DailyLoginGoodsJpanel[] getDailyLoginGoodsJpanel() {
		return dailyLoginGoodsJpanel;
	}

	public void setDailyLoginGoodsJpanel(DailyLoginGoodsJpanel[] dailyLoginGoodsJpanel) {
		this.dailyLoginGoodsJpanel = dailyLoginGoodsJpanel;
	}

	public ImageIcon getIconBack() {
		return iconBack;
	}

	public void setIconBack(ImageIcon iconBack) {
		this.iconBack = iconBack;
	}

	public TaoBaoBtn getCustomBtn() {
		if (customBtn == null) {
			customBtn = new TaoBaoBtn("skin/8100226/button/34.png", 1, "自定义", 70, this);
			customBtn.setBounds(516, 60, 51, 17);
			customBtn.setOpaque(false);
		}
		return customBtn;
	}

	public void setCustomBtn(TaoBaoBtn customBtn) {
		this.customBtn = customBtn;
	}

}
